package algorithm;

import java.util.Arrays;

/**
 * 计数排序
 */
public class CountSort {
    public static void main(String[] args) {
        int[] arr = {9,2,2,3,4,5,7,8,9,0,6,1};
        System.out.println(Arrays.toString(arr));
        couting(arr);
    }
    public static void couting(int[] arr) {
        int[] count = new int[10];
        for ( int i=0;i<arr.length;i++) {
            count[arr[i]]++;
        }
        System.out.println(Arrays.toString(count));
        show(count);
    }
    public static void show(int[] count) {
        String str = "";
        for (int i= 0;i<count.length;i++) {
            if (count[i]> 1) {
                for (int j =0;j<count[i];j++) {
                    //System.out.println(i);
                    str+=i+",";
                }
            } else if (count[i] > 0) {
                //System.out.println(i);
                str+=i+",";
            }
        }
        System.out.println(str);
    }
}
